package com.xiaowu.ai.controller;


import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.List;

@RequestMapping("/chat")
@RestController
public class ChatController {
    @Autowired
    private ChatClient chatClient;

    @RequestMapping("/ai")
    public String chat(String msg){
        return chatClient
                .prompt()
                .user(msg)
                .call()
                .content();
    }

    @RequestMapping(value = "/stream", produces = "text/html;charset=UTF-8")
    public Flux<String> stream(String msg){
        return chatClient
                .prompt()
                .user(msg)
                .stream()
                .content();
    }
}
